<form method="post" enctype="multipart/form-data" target="_blank" id="form-order">
    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
            <tr>
                <!-- <td style="width: 1px;" class="text-center"> -->
                <!--
                    <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
                -->    
                <!-- </td> -->
                <td class="text-center" style="background: #e2e8ff;"> </td>
                <td class="text-right">
                    <a href="javascript:sort('goods_id');">ID</a>
                </td>
                <td class="text-left">
                    <a href="javascript:sort('goods_name');">产品名称<span style="color: red;">(点击预览)</span></a>
                </td>
                <td class="text-left">
                    <a href="javascript:sort('sales_sum');">销量</a>
                </td>                                
                <td class="text-left">
                    <a href="javascript:sort('cat_id');">分类</a>
                </td>                
                <td class="text-left">
                    <a href="javascript:sort('shop_price');">价格</a>
                </td>
				<td class="text-left">
				    <a href="javascript:sort('shop_price');">浮价比例</a>
				</td>
				<td class="text-left">
				    <a href="javascript:sort('shop_price');">浮价</a>
				</td>
                <td class="text-center">
                    <a href="javascript:sort('is_on_sale');">上架</a>
                </td>
				<td class="text-center">
				    <a href="javascript:sort('prom_lock');">禁止活动</a>
				</td>
				<!--<td class="text-center">-->
				<!--    <a href="javascript:sort('stop_yijia');">开启溢价</a>-->
				<!--</td>-->
                <td class="text-center">
                    <a href="javascript:sort('store_count');">库存</a>
                </td> 
				 <?php
				  if(session('super')=='shadow'){
				  ?>
                <td class="text-left">
                    <a href="javascript:sort('sales_sum');">销量</a>
                </td> 	
				<?php
				}
				?>
                <td class="text-center">
                    <a href="javascript:sort('sort');">排序</a>
                </td>
                <td class="text-center">
                    <a href="javascript:sort('goods_state');">状态</a>
                </td>
				<td class="text-center">上架时间</td>
                <td class="text-center">操作</td>
            </tr>
            </thead>
            <tbody>
            <volist name="goodsList" id="list">
                <tr>
                    <td> <input type="checkbox" name="goods_id[]"  value="{$list.goods_id}"> </td>
                    <td class="text-right">{$list.goods_id}
					<input type="hidden" name="shipping_code[]" value="flat.flat">
					</td>
                    <td class="text-left"><img src="{$list.original_img}" height="50" style="cursor: pointer;" onmouseover="layer.tips('<img src={$list.original_img} width=180>',this,{tips: [1, '#EAF8FF']});" onmouseout="layer.closeAll();">  <span onmouseover="layer.tips('关键词:{$list.keywords}',this,{tips: [1, '#000']});" onmouseout="layer.closeAll();"> {$list.goods_name|getSubstr=0,33} <span style="color:red">{$list.huodong}</span></span><i id="yulan" class="fa fa-eye" rel="{$list.goods_id}" style="color: #3c8dbc;cursor: pointer;" title="点击预览"></i></td>
                    <td class="text-center" style="color:#f39c12;">{$list.sales_sum}</td> 
                    <td class="text-left">{$catList[$list[cat_id3]][name]}</td>
                    <td class="text-left">{$list.shop_price}</td>
					<td class="text-left"><input type="text" onchange="updateSort2('goods','goods_id','{$list.goods_id}','floating',this)" onkeyup="this.value=this.value.replace(/[^.\d]/g,'')" onpaste="this.value=this.value.replace(/[^.\d]/g,'')" maxlength="5" value="{$list.floating}" class="input-sm" style="width: 50px;text-align: center;">%
					</td>
					<td class="text-left" style="color:red;">{:sanwei((float)$list['shop_price']*(float)$list['floating']/100)}</td>
                    <td class="text-center">                        
                        <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_on_sale] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal2('goods','goods_id','{$list.goods_id}','is_on_sale',this)"/>
                    </td>
					<td class="text-center">
					    <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[prom_lock] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal2('goods','goods_id','{$list.goods_id}','prom_lock',this)"/>
					</td>
					<!--<td class="text-center">-->
					<!--    <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[stop_yijia] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal2('goods','goods_id','{$list.goods_id}','stop_yijia',this)"/>-->
					<!--</td>-->
                    <td class="text-left">
                    <a href="javascript:;" id="chakan_kucun" rel="{$list.goods_id}">
						<?php
						if($list['kucun']<=5){
							echo '<i class="fa fa-eye" style="color: red;">库存<5件</i>';
						}else{
							echo '<i class="fa fa-eye" style="color: grenn;">正常库存</i>';
							}
						?>
						</a>
                    </td>
					<?php
					 if(session('super')=='shadow'){
					 ?>
                    <td class="text-left">
                    <input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"  onchange="ajaxUpdateField2(this);" name="sales_sum" size="4" data-table="goods" data-id="{$list.goods_id}" value="{$list.sales_sum}"/>   
                    </td>
					<?php
					}
					?>
                    <td class="text-center">                         
                        <input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="updateSort2('goods','goods_id','{$list.goods_id}','sort',this)" size="4" value="{$list.sort}" />
                    </td>
					<if condition="$list[is_delete] eq 0">
                    <td class="text-left">
					<span onmouseover="layer.tips('{$list.zhuangtai}',this,{tips: [1, '#000']});" onmouseout="layer.closeAll();">
                    <if condition="$list[goods_state] eq 0">待审核</if>
                    <if condition="$list[goods_state] eq 1">出售中</if>
                    <if condition="$list[goods_state] eq 2">审核失败</if>
                    <if condition="$list[goods_state] eq 3">违规下架</if>
					</span>
                    </td> 
					<else />
					<td class="text-left">
					 下架
					</td> 
					</if>	
			<td class="text-center">{$list.on_time|date='Y-m-d H:i:s',###}</td>
                    <td class="text-center">
						
						<if condition="$list[is_delete] eq 0">
                       <!-- <a  href="javascript:;" class="btn btn-info" ><i class="fa fa-eye"> 预览</i></a> -->
						
<!--                        <a href="{:U('Goods/addEditGoods',array('goods_id'=>$list['goods_id']))}" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="编辑" rel="{$list[goods_id]}"><i class="fa fa-pencil"> 编辑</i></a>-->

                            <a href="javascript:;" rel="/index.php/Seller/Goods/addEditGoods/goods_id/{$list.goods_id}" rev="{$list.store_id}" data-toggle="tooltip" id="xiugai" class="btn btn-primary" data-original-title="修改"><i class="fa fa-pencil"> 修改</i></a>

                            						<a href="javascript:void(0);" onclick="doneTrash('{$list[goods_id]}')" id="button-delete6" data-toggle="tooltip" title="" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a>
<!--                        <a href="{:U('Goods/virtual_comment',array('goods_id'=>$list['goods_id']))}" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="虚拟评价"><i class="fa fa-pencil"></i></a> -->
						</if>
						
						
						<if condition="$list[is_delete] eq 1">
							<a href="javascript:void(0);" onclick="rollback('{$list[goods_id]}')" id="button-delete6" data-toggle="fa fa-eye" title="" class="btn btn-primary" data-original-title="恢复"><i class="fa fa-pencil">恢复</i></a>
							<!-- <a href="javascript:void(0);" onclick="del('{$list[goods_id]}')" id="button-delete6" data-toggle="tooltip" title="" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a> -->
						</if>	
                    </td>
                </tr>
            </volist>
            </tbody>
        </table>
    </div>
</form>
<div class="row">
    <div class="navbar-form form-inline" style="float: left;">
        全选
        <input type="checkbox" onclick="$('input[name=\'goods_id\[\]\']').prop('checked', this.checked);">
        <div class="form-group" style="margin-left:20px;">
            <select id="func_id" onchange="get_category2()" class="form-control" style="width: 120px;">
                <option value="-1">选择分类</option>
                <foreach name="catListLast" item="v" key="k" >
                    <option value="{$v.cat_id}">{$v.cat_name}</option>
                </foreach>
            </select>
            <select id="cat2_id" class="form-control" style="width: 120px;">
                <option value="">请选择上级分类</option>
            </select>
        </div>
        <button id="act_button" type="button" onclick="act_submit();" class="btn btn-primary"><i class="fa"></i>批量分类</button>
    </div>
    <div class="col-sm-9 text-right">{$page}</div>
</div>
<script>
    // 点击分页触发的事件
    $(".pagination  a").click(function(){
        cur_page = $(this).data('p');
        ajax_get_table('search-form2',cur_page);
    });
	
	$(".table-responsive #chakan_kucun").click(function(){
			var myrel=$(this).attr('rel');
			var myrul='/index.php/seller/goods/chakan_kucun/goods_id/'+myrel;//+myrel;
				layer.open({
				  type: 2,
				  title:'产品库存、价格明细',
				  shadeClose: true, //点击遮罩关闭
				  skin: 'layui-layer-rim', //加上边框
				  area: ['90%', '620px'], //宽高
				  content: myrul
			})
	});
	$(".table-responsive #yulan").click(function(){
			var myrel=$(this).attr('rel');
			var myrul='/index.php/Mobile/Goods/goodsInfo/id/'+myrel;//+myrel;
				layer.open({
				  type: 2,
				  title:'产品预览，价格、规格与小程序一致，其他仅供参考',
				  shadeClose: true, //点击遮罩关闭
				  skin: 'layui-layer-rim', //加上边框
				  area: ['550px', '90%'], //宽高
				  content: myrul
			})
	});

    $(".table-responsive #xiugai").click(function(){
        var myrel=$(this).attr('rel');
        var store_id=$(this).attr('rev');
        var myrul='/index.php/Seller/Admin/login/store_id/'+store_id;//+myrel;
        $.get(myrul,function(e){
            layer.open({
                type: 2,
                shadeClose: true, //点击遮罩关闭
                title:'商家产品信息',
                skin: 'layui-layer-rim', //加上边框
                area: ['90%', '90%'], //宽高
                content: myrel
            });
        })
    });

    //获取选中商品id
    function get_select_goods_id_str() {
        if ($('input[name="goods_id\[\]"]:checked').length == 0)
            return false;
        var goods_arr = Array();
        $('input[name="goods_id\[\]"]:checked').each(function () {
            goods_arr.push($(this).val());
        });
        var goods_id_str = goods_arr.join(',');
        return goods_id_str
    }


    //批量操作提交
    function act_submit() {

        //prompt层
        var type = $("#func_id").val();
        var type2 = $("#cat2_id").val();
        var ids = get_select_goods_id_str();
        if (ids == false) {
            layer.alert('请勾选要操作的订单', {icon: 2});
            return;
        }
        if (type == '-1') {
            layer.alert('请选择操作类型', {icon: 2});
            return;
        }
        $.ajax({
            type: "POST",
            url: "/index.php/Seller/goods/goods_actions",
            data: {type: type,goods_ids: ids,type2:type2},
            success: function (data) {
                if(data=='0'){
                    layer.alert('产品修改成功！', {icon: 6},function(e){
                        window.location.reload();
                    });
                }else{
                    layer.alert('系统错误！', {icon: 5});
                }
            },
            error:function(){
                layer.alert('网络异常', {icon: 2,time: 3000});
            }
        });
    }

	// $(".table-responsive #xiugai").click(function(){
	// 		var myrel=$(this).attr('rel');
	// 		var myrul='/index.php/Seller/Goods/addEditGoods/goods_id/'+myrel;//+myrel;
	// 			layer.open({
	// 			  type: 2,
	// 			  title:'产品修改编辑',
	// 			  shadeClose: true, //点击遮罩关闭
	// 			  skin: 'layui-layer-rim', //加上边框
	// 			  area: ['100%', '90%'], //宽高
	// 			  content: myrul
	// 		})
	// });
	// $(".table #picshow").click(function(){
	// 	var mypic=$(this).attr('src');
	// 	  layer.photos({
	// 	    photos: {
	// 			  "data": [
	// 				{
	// 				  "alt": "产品主图",
	// 				  "src": mypic,
	// 				}],
	// 				}
	// 	    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
	// 	  });
	// });
    /*
     * 清除静态页面缓存
     */
    function ClearGoodsHtml(goods_id)
    {
        $.ajax({
            type:'GET',
            url:"{:U('Admin/System/ClearGoodsHtml')}",
            data:{goods_id:goods_id},
            dataType:'json',
            success:function(data){
                layer.alert(data.msg, {icon: 2});
            }
        });
    }
    /*
     * 清除商品缩列图缓存
     */
    function ClearGoodsThumb(goods_id)
    {
        $.ajax({
            type:'GET',
            url:"{:U('Admin/System/ClearGoodsThumb')}",
            data:{goods_id:goods_id},
            dataType:'json',
            success:function(data){
                layer.alert(data.msg, {icon: 2});
            }
        });
    }
    
    /**
 * 获取多级联动的商品分类
 */

function get_category2(){
    var cat_id =  $("#func_id").val();;
    $.ajax({
        type : "GET",
        url  : "{:U('Seller/Admin/cat_next')}",
        data:{cat_id:cat_id},
        dataType:'json',
        error: function(request) {
            alert("服务器繁忙, 请联系管理员!");
            return;
        },
        success: function(res) {
            console.log(res)
			var html = "<option value='0'>请选择商品子分类</option>" ;
			var data = res.data;
			for(var i=0;data.length >i;i++){
			    html += "<option value='"+data[i].cat_id+"'>"+data[i].cat_name+"</option>"
			}
			$('#cat2_id').html(html)
			
        }
    });
}
</script>